
import twitterT
import operator

babaovo_username = 'username'
babaovo_password = 'password'

A_pos = 1

def babaovoByPages(user,all=False,count=200):
	api = twitterT.Api(babaovo_username,babaovo_password)
	
	statusFlag = True
	page=1
	babaovo = {}
	total = 0
	while statusFlag:
		print "Loading page..." + str(page)
		statusList = api.GetUserTimeline(user,count=count,page=page)
		if len(statusList) > 0:
			total += len(statusList)
			for st in statusList:
				status = st.GetText()
				if status.startswith('RT'):
					try:
						babaovo[rt(status)] = babaovo[rt(status)] + 1
					except:
						babaovo[rt(status)] = 1
			page+=1
		else:
			statusFlag = False
		
	print str(total) + "status read."
		
	if all:
		babaovo = babaovo.items()
		babaovo.sort(key=operator.itemgetter(1))
		babaovo.reverse()
		return babaovo
	else:
		name = max(babaovo,key= lambda a: babaovo.get(a))
		value = babaovo.get(name)
		return name,value




def rt(status):
	#Get the name of the user that originated the RT.
	return status.split()[A_pos].strip('@:;!*&%$#-=+')
	
	
if __name__ == '__main__':
	print babaovoByPages('ebarreiros',True)
